<?php
function remote_file_size($link)
	{
        $remoteFile =$link;
        $ch = curl_init($remoteFile);
        curl_setopt($ch, CURLOPT_NOBODY, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
        $data = curl_exec($ch);
        curl_close($ch);
        $contentLength = 'Unknown';
        if (preg_match('/Content-Length: (\d+)/', $data, $matches)) {
        $contentLength = round(((int)$matches[1])/1024/1024,2);}
        return $contentLength;
  	}
function dehash($hash,$key)
{ 
   sql();	
   $cmd="SELECT * FROM `".$key."` WHERE ".$key."_hash='".$hash."'";
   $excute=mysql_query($cmd);
   if (mysql_num_rows($excute)==0) return 0; else
   {
      $info=mysql_fetch_assoc($excute);
	  $khash=$key.'_id';
	  return $info[$khash];
   }
}
function dehash2($hash)
{ 
   sql2();	
   $cmd="SELECT * FROM `user` WHERE user_hash='".$hash."'";
   $excute=mysql_query($cmd);
   if (mysql_num_rows($excute)==0) return 0; else
   {
      $info=mysql_fetch_assoc($excute);
	  return $info['userid'];
   }
   sql();
}
function readword($word,$n){
if (strlen($word)<=$n) return $word.'...'; else
return substr($word,0,$n).'...';
}
function changetime($time)
{
$longtime=time()-$time;
if ($longtime>=31556926) $result=round($longtime/31556926,0).' năm'; else
if ($longtime>=2629743)  $result=round($longtime/2629743,0).' tháng'; else
if ($longtime>=86400) $result=round($longtime/86400,0).' ngày'; else
if ($longtime>=3600) $result=round($longtime/3600,0).' giờ'; else
if ($longtime>=60) $result=round($longtime/60,0).' phút'; else $result=$longtime.' giây';
 return $result;   
}
function hashencode($id)
{
$hashnum=1050382+$id;
$hashtable='AZNPLMXYDW';
$strhash=strval($hashnum);
$hash='';
for ($i=0;$i<strlen($strhash);$i++)
{
   $k=intval($strhash[$i]);
   $hash.=$hashtable[$k];
}
return $hash;
}

function isolink($word)
{return str_replace(' ','-',convert($word));}
function isolink2($word)
{return str_replace(' ','-',$word);}

function finduser($id){
sql2();
$cmd="SELECT * FROM `user` WHERE userid=".$id;
$info=mysql_fetch_assoc(mysql_query($cmd));
sql();
return $info['username'];
}
function getuser(){
	chdir('/home/cailuong/public_html/beta/template/forum/');
    require_once('./global.php');
	return $vbulletin->userinfo;
}
function getinfo(){
	chdir('/home/cailuong/public_html/beta/template/forum/');
    require_once('./global.php');
	return $vbulletin->userinfo;
}
function nofile()
{
	$user=getuser();
	$curdir=getcwd();
	chdir('/home/cailuong/public_html/beta/data/upload/fd8543acb46544ff94e40e4a957550cd/');
	$file=scandir(md5($user['userid']).'/');
	chdir($curdir);
	if (!$file[2]) return true; else return false;
}
function nofilef()
{
	$user=getuser();
	$curdir=getcwd();
	chdir('/home/cailuong/public_html/beta/template/forum/data/upload/fd8543acb46544ff94e40e4a957550cd/');
	$file=scandir(md5($user['userid']).'/');
	chdir($curdir);
	if (!$file[2]) return true; else return false;
}
function addmenu($menu,$name){
	$link='?menu='.$menu;
	$id=$_GET['menu'];
	echo'<li'; 
	if ($id==$menu) echo ' class="mark">'; else echo '>'; 
		echo '<a href="'.$link.'"><span>'.$name.'</span></a></li>';
}
?>
